/*
 * @Description: 
 * @Version: 1.0
 * @Autor: etonetech
 * @Date: 2022-10-08 09:18:24
 * @LastEditors: etonetech
 * @LastEditTime: 2022-11-28 16:58:07
 */
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const Encrypt = {

  encode: function (n: string) {
    var e, o, a, r, i, c, s, d = "", l = 0;
    for (n = this._utf8_encode(n); l < n.length;)
      e = n.charCodeAt(l++),
        o = n.charCodeAt(l++),
        a = n.charCodeAt(l++),
        r = e >> 2,
        i = (3 & e) << 4 | o >> 4,
        c = (15 & o) << 2 | a >> 6,
        s = 63 & a,
        isNaN(o) ? c = s = 64 : isNaN(a) && (s = 64),
        d = d + t.charAt(r) + t.charAt(i) + t.charAt(c) + t.charAt(s);
    return d
  },
  decode: function (n: string) {
    var e, o, a, r, i, c, s, d = "", l = 0;
    for (n = n.replace(/[^A-Za-z0-9\+\/\=]/g, ""); l < n.length;)
      r = t.indexOf(n.charAt(l++)),
        i = t.indexOf(n.charAt(l++)),
        c = t.indexOf(n.charAt(l++)),
        s = t.indexOf(n.charAt(l++)),
        e = r << 2 | i >> 4,
        o = (15 & i) << 4 | c >> 2,
        a = (3 & c) << 6 | s,
        d += String.fromCharCode(e),
        64 != c && (d += String.fromCharCode(o)),
        64 != s && (d += String.fromCharCode(a));
    return d = this._utf8_decode(d)
  }
  ,
  _utf8_encode: function (t: string) {
    t = t.replace(/\r\n/g, "\n");
    for (var n = "", e = 0; e < t.length; e++) {
      var o = t.charCodeAt(e);
      128 > o ? n += String.fromCharCode(o) : o > 127 && 2048 > o ? (n += String.fromCharCode(o >> 6 | 192),
        n += String.fromCharCode(63 & o | 128)) : (n += String.fromCharCode(o >> 12 | 224),
          n += String.fromCharCode(o >> 6 & 63 | 128),
          n += String.fromCharCode(63 & o | 128))
    }
    return n
  }
  ,
  _utf8_decode: function (t: string) {
    for (var n = "", e = 0, o = 0, c1 = 0, c2 = 0, c3 = 0; e < t.length;)
      o = t.charCodeAt(e),
        128 > o ? (n += String.fromCharCode(o),
          e++) : o > 191 && 224 > o ? (c2 = t.charCodeAt(e + 1),
            n += String.fromCharCode((31 & o) << 6 | 63 & c2),
            e += 2) : (c2 = t.charCodeAt(e + 1),
              c3 = t.charCodeAt(e + 2),
              n += String.fromCharCode((15 & o) << 12 | (63 & c2) << 6 | 63 & c3),
              e += 3);
    return n
  },
  randomDecode: function (val: string) {
    if (!val) {
      return ''
    }
    // let t=this.encode(val)
    let t = val
    var n = ""
    for (var o = 0; o < t.length; o++) {
      if (o < t.length - 3 && (o & 1) == 1) {
        n += t[o]
      }
      if (o >= t.length - 3) {
        n += t[o]
      }
    }

    return this.decode(n)
  },
  randomEncode: function (val: string) {
    let t = this.encode(val)
    for (var n = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", o = 0; o < t.length; o++)
      n += (o > t.length - 3 ? "" : e.charAt(Math.floor(Math.random() * e.length))) + t[o];
    return n
  }
}

export default Encrypt